package likou.tanxin;

/**
 * @Info:
 * @Author: Tangxz
 * @Date: 2020/09/07 09:14
 */
public class _44 {
    public static void main(String[] args) {
        System.out.println(isMatch("acdcb", "a*c?b"));
    }

    public static boolean isMatch(String s, String p) {
        int j = 0;
        int start = 0;
        int last = 0;
        for (int i = 0; i < s.length(); ) {
            if (j < p.length() && (s.charAt(i) == p.charAt(j) || p.charAt(j) == '?')) {
                i++;
                j++;
            } else if (j < p.length() && p.charAt(j) == '*') {
                last = i;
                start = ++j;
            } else if (start != 0) {
                i = ++last;
                j = start;
            } else {
                return false;
            }
        }
        while (j < p.length() && p.charAt(j) == '*') {
            j++;
        }
        return j == p.length();
    }
}
